function  [Total_SW,Total_SW_experience,Total_W_avg,Total_ext_avg,Total_gvt_avg]=Total_Welfare_clogit_EEgap(weight,param,param_FE,param_FEdemo,id_ij,J,p_elec,t_pigou,d_ext,elec,lifetime,r,MCPF)

global state_i week_i J T S MT MTvector K WB...
price price_denom rebate_estar_denom estar_denom kwh prod_denom...
id_i id_j id_ij id_m id_n  demo pidnest choicenest_ij brandweek_denom ...
type_id2_3_demo1_num type_id2_3_demo1_denom type_id3_demo1_num type_id3_demo1_denom AV_demo1_num AV_demo1_denom  ice_sc_demo1_num ice_sc_demo1_denom...
type_id2_3_demo2_num type_id2_3_demo2_denom type_id3_demo2_num type_id3_demo2_denom AV_demo2_num AV_demo2_denom  ice_sc_demo2_num ice_sc_demo2_denom...
type_id2_3_demo3_num type_id2_3_demo3_denom type_id3_demo3_num type_id3_demo3_denom AV_demo3_num AV_demo3_denom  ice_sc_demo3_num ice_sc_demo3_denom...
type_id2_3_demo4_num type_id2_3_demo4_denom type_id3_demo4_num type_id3_demo4_denom AV_demo4_num AV_demo4_denom  ice_sc_demo4_num ice_sc_demo4_denom...
type_id2_3_demo5_num type_id2_3_demo5_denom type_id3_demo5_num type_id3_demo5_denom AV_demo5_num AV_demo5_denom  ice_sc_demo5_num ice_sc_demo5_denom...
type_id2_3_demo6_num type_id2_3_demo6_denom type_id3_demo6_num type_id3_demo6_denom AV_demo6_num AV_demo6_denom  ice_sc_demo6_num ice_sc_demo6_denom;


    param_FE_k=param_FE;
	param_FEdemo_k=param_FEdemo;

dim_k=length(weight)
%parfor k=1:dim_k
for k=1:dim_k

	param_k=param{k};

[Error_i{k}, CS_i{k}, W_i{k}, W_experience_i{k},  Error_avg(k), CS_avg(k), W_avg(k), W_experience_avg(k), ext_i{k}, ext_avg(k), ext_experience_i{k}, ext_experience_avg(k), P_decision_j{k}, P_experience_j{k},gvt_i{k},gvt_avg(k),SW_i{k},SW_avg(k),gvt_experience_i{k},gvt_experience_avg(k),SW_experience_i{k},SW_experience_avg(k)]=Welfare_k_clogit_EEgap(param_k,param_FE_k,param_FEdemo_k,id_ij,J,p_elec,t_pigou,d_ext,elec,lifetime,r,MCPF);


end

	Total_SW=sum(weight'.*SW_avg);
	Total_SW_experience=sum(weight'.*SW_experience_avg);
	Total_W_avg=sum(weight'.*W_avg);
	Total_ext_avg=sum(weight'.*ext_avg);
	Total_gvt_avg=sum(weight'.*gvt_avg);
 
end